// pages/shangquan/shangquan.js
const app=getApp();
const util = require("../../utils/util.js");
const baseImgUrl = util.baseImgUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    position:"全城全城",//默认 为全城
    arrow_d:baseImgUrl+"arrow_d.png",
    activeTopIndex:1,//默认选择 推荐
    shaixuanUrl:baseImgUrl+"shaixuan.png",
    activeIndex:0,//导航栏默认选择推荐
    nomore:"~没有更多动态~",//到底提示
    classesBar:"为您精选以下标签",
    showclasses:false,//是否显示分类面板。默认不显示
    activeClass:0,//默认选择分类的第一个
    showAreas:false,//选择商圈面板，默认不显示
    arrow_red: baseImgUrl +"arrow_red.png",//红色箭头
    activeArea:0,//默认选择附近选项
    activeQuan:0,//默认选择全部商圈
    certifyUrl: baseImgUrl+"certifidImg.png",//已认证图片路径
    uncertifyUrl: baseImgUrl+"uncertifyImg.png",//未认证图片路径
    hotUrl: baseImgUrl+"hot.png",//人气图片路径
    positionUrl: baseImgUrl+ "position.png",//距离图片路径
    distance: 5,//测试数据  距离
    followedUrl: baseImgUrl+ "followed.png",//已关注的图片路径
    unfollowUrl: baseImgUrl+"unfollowed.png",//未关注的图片路径
    scrollLeft: 0,
    greyshow: false,//是否显示弹出框 ture--显示 false--隐藏
    isHideLoadMore: true,
    followFlag: true,
    myclass:"分类",
    topList:[{
      id:0,
      name:"关注"
    }, {
        id: 1,
        name: "推荐"
      }, {
        id: 2,
        name: "榜单"
      }
    ],
    navlist: [{
      id: 0,
      name: "推荐",
    },
    {
      id: 1,
      name: "今日上新",
    },
    {
      id: 2,
      name: "店铺活动",
    }, {
      id: 3,
      name: "限时抢购",
    }, {
      id: 4,
      name: "特价促销",
    }, {
      id: 5,
      name: "店铺活动",
    }, {
      id: 6,
      name: "限时抢购",
    }, {
      id: 7,
      name: "特价促销",
    }],
    shoplist:[{
      id:0,
      shoplogo:baseImgUrl+"shoplogo.png",
      shopname:"海蓝之谜",
      date:"2018.9.3",
      introduce:"会计学中商品的定义是 商品流通企业外购或 委托加工完成， 验收入库用于销售的各种商品。在人教版必修一政治书中的定义是用于交换的劳动产品。商品的基本属性是价值和 使用价值。",
      goodspic:[{
        id:"pic0",
        picurl:baseImgUrl+"good3.png",
      }, {
          id: "pic1",
          picurl: baseImgUrl + "goods2.png",
        }, {
          id: "pic2",
          picurl: baseImgUrl + "goods1.png",
        }, {
          id: "pic3",
          picurl: baseImgUrl + "goods2.png",
        }, {
          id: "pic4",
          picurl: baseImgUrl + "goods1.png",
        }],
      labellist:["#店铺活动#"]

    }, {
        id: 0,
        shoplogo: baseImgUrl + "shoplogo.png",
        shopname: "海蓝之谜",
        date: "2018.9.3",
        introduce: "会计学中商品的定义是 商品流通企业外购或 委托加工完成， 验收入库用于销售的各种商品。在人教版必修一政治书中的定义是用于交换的劳动产品。商品的基本属性是价值和 使用价值。",
        goodspic: [{
          id: "pic0",
          picurl: baseImgUrl + "goods1.png",
        }, {
            id: "pic1",
            picurl: baseImgUrl + "goods2.png",
          }, {
            id: "pic2",
            picurl: baseImgUrl + "goods1.png",
          }, {
            id: "pic3",
            picurl: baseImgUrl + "goods2.png",
          }, {
            id: "pic4",
            picurl: baseImgUrl + "goods1.png",
          }],
        labellist: ["#今日上新#"]

      }],
    classesList:[{
      id:0,
      name:"全部"
    },{
        id: 1,
        name: "营养保健"
      },{
        id: 0,
        name: "个人洗护"
      }, {
        id: 2,
        name: "母婴"
      },{
        id: 3,
        name: "运动"
      }, {
        id: 4,
        name: "补给"
      }],
    areas:[{
      id:0,
      area:"附近",
      num: ''
    },{
        id:1,
        area: "推荐商圈",
        num:''
      }, {
        id: 2,
        area: "云龙区",
        num: 90
      },{
        id: 3,
        area: "鼓楼区",
        num: 90
      }, {
        id: 4,
        area: "泉山区",
        num: 90
      }, {
        id:5,
        area: "铜山区",
        num: 90
      }, {
        id: 6,
        area: "贾汪区",
        num: 90
      }, {
        id: 7,
        area: "沛县",
        num: 90
      }, {
        id: 7,
        area: "丰县",
        num: 90
      }],
    shangquan:[
      {
        id: 0,
        quan: "全部商圈",
        num: ''
      }, {
        id: 1,
        quan: "彭城一号",
        num: 25
      }, {
        id: 2,
        quan: "云龙万达",
        num: 10
      }, {
        id: 3,
        quan: "矿业大学",
        num: 90
      }, {
        id: 4,
        quan: "1818美食广场",
        num: 20
      }, {
        id: 5,
        quan: "牌楼",
        num: 12
      }, {
        id: 6,
        quan: "段庄广场",
        num: 90
      }, {
        id: 7,
        quan: "三胞广场",
        num: 90
      }, {
        id: 8,
        quan: "美好汇邻湾",
        num: 90
      }
    ],
    shoplists: [{
      shopid: 1,
      xuhao: 1,
      shoplogo: "../images/bang.png",
      shopname: "巴黎欧莱雅徐州总店",
      certify: true,
      cerbifyUrl: "../images/certify.png",
      hotNum: 1520,
      latitude: "35.0125",
      longitude: "117.35632",
      followFlag: true,
      picrul: [{
        url: "../images/pic0.png",
        price: "56"
      }, {
        url: "../images/pic0.png",
        price: "50"
      }, {
        url: "../images/pic0.png",
        price: "9.9"
      }
      ]
    }, {
      shopid: 2,
      xuhao: 2,
      shoplogo: "../images/bang.png",
      shopname: "巴黎欧莱雅徐州2店",
      certify: false,
      cerbifyUrl: "../images/uncertify.png",
      hotNum: 1500,
      latitude: "35.0125",
      longitude: "117.35632",
      followFlag: false,
      picrul: [{
        url: "../images/pic0.png",
        price: "56"
      }, {
        url: "../images/pic0.png",
        price: "30"
      }, {
        url: "../images/pic0.png",
        price: "9.9"
      }
      ]
    }, {
      shopid: 1,
      xuhao: 3,
      shoplogo: "../images/bang.png",
      shopname: "巴黎欧莱雅徐州总店",
      certify: true,
      cerbifyUrl: "../images/certify.png",
      hotNum: 1520,
      latitude: "35.0125",
      longitude: "117.35632",
      followFlag: true,
      picrul: [{
        url: "../images/pic0.png",
        price: "56"
      }, {
        url: "../images/pic0.png",
        price: "50"
      }, {
        url: "../images/pic0.png",
        price: "9.9"
      }
      ]
    }, {
      shopid: 2,
      xuhao: 4,
      shoplogo: "../images/bang.png",
      shopname: "巴黎欧莱雅徐州2店",
      certify: false,
      cerbifyUrl: "../images/uncertify.png",
      hotNum: 1500,
      latitude: "35.0125",
      longitude: "117.35632",
      followFlag: false,
      picrul: [{
        url: "../images/pic0.png",
        price: "56"
      }, {
        url: "../images/pic0.png",
        price: "30"
      }, {
        url: "../images/pic0.png",
        price: "9.9"
      }
      ]
    }]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      wx.getLocation({
        success: function(res) {
          console.log(res);

          //请求后台，获取初始数据
          //当前商圈，顶部分类，分类，活动类型
          var that=this;
          var topIndex=that.data.activeTopIndex;
        },
        fail:function(err){
          console.log(err);
          console.log("定位失败");
        }
      })
  },

  /********点击顶部********** */
  choseTop:function(e){
    console.log(e);
    var that=this;
    var activeTopIndex=e.currentTarget.dataset.index;
    that.setData({
      activeTopIndex: activeTopIndex
    })

    //调用接口，请求数据
    
  },

  /*************点击全城******** */
  showAreas:function(){
    var that=this;
    var showAreas = that.data.showAreas;
    if (!showAreas){
      that.setData({
        showAreas:true
      })
    }else{
      that.setData({
        showAreas: false
      })
    }
  },
//选择区域
  choseArea:function(e){
    var that=this;
    var activeArea=e.currentTarget.dataset.index;
    var thisid=e.currentTarget.dataset.id;
    that.setData({
      activeArea:activeArea
      
    })
    //请求数据，拿到商圈

  },

  /********选择商圈********** */
  choseQuan:function(e){
    var that = this;
    var activeQuan = e.currentTarget.dataset.index;
    var thisid = e.currentTarget.dataset.id;
    var quanName=e.currentTarget.dataset.quan;
    console.log(quanName)
    that.setData({
      activeQuan: activeQuan,
      position:quanName
    })
    //请求数据，

    util.loading();
    setTimeout(function(){
      that.setData({
        showAreas: false
      })
    },500)
    
  },

  /*******选择类别**********/
  choseNav: function (e) {
    console.log(e);
    var that = this;
    var activeIndex = e.currentTarget.dataset.index;
    that.setData({
      activeIndex: activeIndex,
      toview: "item" + activeIndex,
     
    })
    util.loading();

  },

  /*********选择右侧的分类，显示分类面板******** */
  showclasses:function(){
    var that=this;
    var showclasses=that.data.showclasses;

      if(!showclasses){
        that.setData({
          showclasses:true
        })
      }else{
        that.setData({
          showclasses: false
        })
      }
  },

  /********点击分类************* */
  choseClass:function(e){
      var that=this;
      var activeClass=e.currentTarget.dataset.index;
      var classesId=e.currentTarget.dataset.id;
    var classname = e.currentTarget.dataset.classname;
      var activeTop = that.data.activeTopIndex;
      var activeNav = that.data.activeIndex;
    
    console.log(activeTop + "****" + activeNav + "*********" + activeClass);
     
      that.setData({
        activeClass: activeClass,
        myclass: classname,
        showclasses:false
      })
  },

  /**********隐藏弹出层********* */
  hideGrey:function(){
    var that=this;
    that.setData({
      showAreas:false,
      showclasses: false
    })
  },

  /********添加关注**************/
  guanzhu:function(e){
    var that=this;
   
    var thisId=e.currentTarget.dataset.id;
    var thisIndex=e.currentTarget.dataset.index;
    that.data.shoplists[thisIndex].followFlag=true;
    console.log(e);
    that.setData({
     
      shoplists: that.data.shoplists
    })

    
      
  },

  /**************取消关注*************** */
  quxiaoguanzhu:function(e){
    var that = this;
    var thisId = e.currentTarget.dataset.id;
    var thisIndex = e.currentTarget.dataset.index;
   wx.showModal({
    
     content: '确认取消关注',
     showCancel: true,
     cancelText: '取消',
     cancelColor: '#666',
     confirmText: '确定',
     confirmColor: '#ff1314',
     success: function(res) {
       if (res.confirm) {
         that.data.shoplists[thisIndex].followFlag = false;
         that.setData({

           shoplists: that.data.shoplists
         })
       } else if (res.cancel) {
         console.log('用户点击取消')
       }
      
     },
     fail: function(res) {
       console.log("失败");
     },
     complete: function(res) {
       console.log("完成");
     },
   })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})